/**
 * 基础performance指标检测类
 */
class PerformanceCollect{
    constructor(timing){
        this.dns = {
            name: "DNS解析耗时",
            time: timing.domainLookupEnd - timing.domainLookupStart
        }
        this.tcp = {
            name: "TCP连接耗时",
            time: timing.connectEnd - timing.connectStart
        }
        this.ssl = {
            name: "SSL安全连接耗时",
            // 针对http请求可能出现无安全连接的情况
            time: timing.secureConnectionStart != 0 ? timing.connectEnd - timing.secureConnectionStart : 0
        }
        this.ttfb = {
            name: "网络请求耗时",
            time: timing.responseStart - timing.requestStart
        }
        this.transport = {
            name: "数据传输耗时",
            time: timing.responseEnd - timing.responseStart
        }
        this.dom = {
            name: "DOM解析耗时",
            time: timing.domInteractive - timing.responseEnd
        }
        this.source = {
            name: "资源加载耗时",
            time: timing.loadEventStart - timing.domContentLoadedEventEnd
        }
        this.firstByte = {
            name: "第一个字节到达时间",
            time: timing.responseStart - timing.domainLookupStart
        }
        this.white = {
            name: "白屏时间",
            time: timing.responseEnd - timing.fetchStart
        }
        this.interaction = {
            name: "首次可交互时间",
            time: timing.domInteractive - timing.fetchStart
        }
        this.domReady = {
            name: "DOM准备就绪时间",
            time: timing.domContentLoadEventEnd - timing.fetchStart
        }
        this.loaded = {
            name: "页面完全加载完毕",
            time: timing.loadEventStart - timing.fetchStart
        }
    }
}


module.exports = {
    PerformanceCollect
}